package com.training.java.core.collections.car.pre15;

/**
 * Creating a School Class with attributes name,city,school district,great
 * school ranking. Attributes name, city,schoolDistrict fields are String Type,
 * schoolRakning field is int type.
 * 
 */
public class School {

	private String name;
	private String city;
	private String schoolDistrict;
	private int schoolRanking;

	// Getters to get the info about the instance variables.

	public int getSchoolRanking() {
		return schoolRanking;
	}

	public String getName() {
		return name;
	}

	public String getCity() {
		return city;
	}

	public String getSchoolDistrict() {
		return schoolDistrict;
	}

	// Setter Method to set the school Ranking
	public void setSchoolRanking(int schoolRanking) {
		this.schoolRanking = schoolRanking;
	}

	/**
	 * @param city
	 *            the city to set
	 */
	public void setCity(String city) {
		this.city = city;
	}

	/**
	 * @param schoolDistrict
	 *            the schoolDistrict to set
	 */
	public void setSchoolDistrict(String schoolDistrict) {
		this.schoolDistrict = schoolDistrict;
	}

	// Constructor for immutable objects

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	public School(String name, String city, String schoolDistrict) {
		this.name = name;
		this.city = city;
		this.schoolDistrict = schoolDistrict;
	}

	// Constructor for mutable objects

	public School() {

	}

	/**
	 * Here the requirement is
	 * "name, city and school district together define equality" finding the
	 * equality by overriding the equals and hashCode
	 */

	@Override
	public boolean equals(Object obj) {

		// checking the parameter is real time object or not.
		// if it is not real object, it should
		// return False.

		if (obj instanceof School)

		{
			School school1 = (School) obj; // Casting
			return this.name.equals(school1.name)
					&& this.city.equals(school1.schoolDistrict);// &&this.schoolRanking.equals(school1.schoolRanking);

		} else {
			return false;

		}

	}// end of equals method

	// Overriding the hashCode

	@Override
	public int hashCode() {
		return name.hashCode() + city.hashCode() + schoolDistrict.hashCode();// +schoolRanking.hashCode()
	}

}
